package icu.qx.qc.service.impl;

import java.util.*;

import icu.qx.qc.domain.QcDrawback;
import icu.qx.qc.domain.QcQualityProject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import icu.qx.qc.mapper.QcQualityQprojectMapper;
import icu.qx.qc.domain.QcQualityQproject;
import icu.qx.qc.service.IQcQualityQprojectService;

/**
 * 质检项目质检情况Service业务层处理
 *
 * @author yong
 * @date 2024-06-25
 */
@Service
public class QcQualityQprojectServiceImpl implements IQcQualityQprojectService {
    @Autowired
    private QcQualityQprojectMapper qcQualityQprojectMapper;

    @Override
    public List<QcQualityProject> selectQcQualityQprojectByQqProCheckCode(String qqProCheckCode) {
        List<QcQualityQproject> qcQualityQprojects = qcQualityQprojectMapper.selectQcQualityQprojectByQqProCheckCode(qqProCheckCode);

        Map<String, QcQualityProject> qualityProjectMap = new HashMap<>();
        qcQualityQprojects.forEach(e -> {
            String qualityCode = e.getQqQualityCode();
            QcQualityProject qcQualityProject = qualityProjectMap.getOrDefault(qualityCode, e.getQcQualityProject());
            qcQualityProject.getDrawbackList().add(e.getQcDrawback());
            qualityProjectMap.put(qualityCode, qcQualityProject);
        });

        return new ArrayList<>(qualityProjectMap.values());
    }

    /**
     * 新增质检项目质检情况
     *
     * @param qcQualityQproject 质检项目质检情况
     * @return 结果
     */
    @Override
    public int insertQcQualityQproject(QcQualityQproject qcQualityQproject) {
        return qcQualityQprojectMapper.insertQcQualityQproject(qcQualityQproject);
    }

    /**
     * 批量删除质检项目质检情况
     *
     * @param qqProCheckCodes 需要删除的质检项目质检情况主键
     * @return 结果
     */
    @Override
    public int deleteQcQualityQprojectByQqProCheckCodes(String[] qqProCheckCodes) {
        return qcQualityQprojectMapper.deleteQcQualityQprojectByQqProCheckCodes(qqProCheckCodes);
    }

    /**
     * 删除质检项目质检情况信息
     *
     * @param qqProCheckCode 质检项目质检情况主键
     * @return 结果
     */
    @Override
    public int deleteQcQualityQprojectByQqProCheckCode(String qqProCheckCode) {
        return qcQualityQprojectMapper.deleteQcQualityQprojectByQqProCheckCode(qqProCheckCode);
    }
}
